package com.wish.banking.controller;


import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.wish.banking.entity.TJrProduct;
import com.wish.banking.entity.vo.ProductVo;
import com.wish.banking.service.ITJrProductService;
import com.wish.common.core.usconfig.common.MsgResult;
import com.wish.common.security.utils.SecurityUtils;
import com.wish.system.api.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 高露雯:金融产品表 前端控制器
 * </p>
 *
 * @author benjamin
 * @since 2022-04-05
 */
@RestController
@RequestMapping("/product")
public class TJrProductController {

    @Autowired
    ITJrProductService itJrProductService;

    @GetMapping("/productList")
    public MsgResult productList(ProductVo qv) {
        PageInfo<ProductVo> pg = itJrProductService.productList(qv);
        return MsgResult.succeed(pg);
    }

    @GetMapping("/getProductMsg")
    public MsgResult getMsg(ProductVo qv) {
        ProductVo productVo = itJrProductService.getMsg(qv);
        return MsgResult.succeed(productVo);
    }

    @PostMapping("/letuout")
    public MsgResult letuout(@RequestBody ProductVo qv) {
        int x = itJrProductService.letuout(qv);
        return MsgResult.succeed();
    }


    @PutMapping("/updateProduct")
    public MsgResult updateProduct(@RequestBody TJrProduct jrProduct) {
        Long userId = SecurityUtils.getUserId();
        jrProduct.setUpdateUserid(userId);
        jrProduct.setUpdateTime(new Date());
        itJrProductService.updateById(jrProduct);
        return MsgResult.succeed();
    }

    @PostMapping("/saveProduct")
    public MsgResult saveProduct(@RequestBody TJrProduct jrProduct) {
        Date date = new Date();
        Long userId = SecurityUtils.getUserId();
        jrProduct.setCreateTime(date);
        jrProduct.setCreateUserid(userId);
        jrProduct.setUpdateUserid(userId);
        jrProduct.setUpdateTime(date);
        itJrProductService.save(jrProduct);
        return MsgResult.succeed();
    }

    @GetMapping("/getCapName")
    public MsgResult getCapName() {
        List<TJrProduct> list = itJrProductService.getCapName();
        return MsgResult.succeed(list);
    }

}
